package gui.funcionarios;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.border.BevelBorder;

import ge.escola.Escola;
import ge.usuarios.Diretor;
import ge.usuarios.Professor;
import ge.util.Data;
import ge.util.Validadores;
import gui.GerenciadorDeJanelas;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Professor.java
 *
 * Created on 05/11/2010, 16:07:01
 */


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 *
 * @author Caio
 */

public class DiretorPanel extends javax.swing.JPanel {
        private boolean flag = true;
        private String nome;
        private int matricula;
        private String cpf;
        private String endereco;
        private Data dataAdmissao;
        private String diaAdm;
        private String mesAdm;
        private String anoAdm;
        private Data dataPosse;
        private String diaPosse;
        private String mesPosse;
        private String anoPosse;
        private String telefone;
        private String email;
        private ArrayList<Integer> listaMatriculas = new ArrayList();
        private Validadores valida = new Validadores();
        private String foto;
        private String cargo;
        private List<Integer> todasMatriculas;
        private String cpf1;
        private String cpf2;
        private String cpf3;
        private JLabel jLabel10;
        private JLabel jLabel7;
        private JLabel ponto;
        private JTextField caixaPosse3;
        private JTextField caixaPosse2;
        private JTextField caixaAdm3;
        private JTextField caixaAdm2;
        private JButton addFoto;
        private JTextField caixaTel1;
        private JTextField caixaTel3;
        private JTextField caixaTel2;
        private String cpf4;
        private String telefone1;
        private String telefone2;
        private String telefone3;
    /** Creates new form Professor */
    public DiretorPanel() {
        initComponents();
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        this.setLayout(null);
        this.setSize(800, 600);
        this.setBackground(new java.awt.Color(204,204,255));
        cadastra = new javax.swing.JButton();
        this.add(cadastra);
        cancelar = new javax.swing.JButton();
        limpar = new javax.swing.JButton();
        this.add(limpar);
        this.add(cancelar);
        caixaNome = new javax.swing.JTextField();
        caixaNome.setFont(new java.awt.Font("Tahoma",0,18));
        caixaEnd = new javax.swing.JTextField();
        caixaEnd.setFont(new java.awt.Font("Tahoma",0,18));
        caixaMail = new javax.swing.JTextField();
        caixaMail.setFont(new java.awt.Font("Tahoma",0,18));
        caixaAdm = new javax.swing.JTextField();
        caixaAdm.setFont(new java.awt.Font("Tahoma",0,18));
        caixaAdm.setText("DD");
        caixaAdm.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent evt) {
                        if(caixaAdm.isEditable()){
                                        caixaAdm.setText("");
                                }
                        
                }
        });
        caixaPosse = new javax.swing.JTextField();
        caixaPosse.setFont(new java.awt.Font("Tahoma",0,18));
        caixaPosse.setText("DD");
        caixaPosse.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent evt) {
                        if(caixaPosse.isEditable()){
                                        caixaPosse.setText("");
                                }
                        
                }
        });
        caixaFoto = new javax.swing.JTextField();
        caixaFoto.setFont(new java.awt.Font("Tahoma",0,18));
        c1 = new javax.swing.JLabel();
        c2 = new javax.swing.JLabel();
        c3 = new javax.swing.JLabel();
        c4 = new javax.swing.JLabel();
        c5 = new javax.swing.JLabel();
        c6 = new javax.swing.JLabel();
        c7 = new javax.swing.JLabel();
        c9 = new javax.swing.JLabel();

        jLabel6.setFont(new java.awt.Font("Arial",0,24));
        jLabel6.setText("Data de admissao:");
        jLabel6.setForeground(new java.awt.Color(0,102,102));

        jLabel9.setFont(new java.awt.Font("Arial",0,24));
        jLabel9.setText("Caminho da foto:");
        jLabel9.setForeground(new java.awt.Color(0,102,102));
        {
                caixaCpf = new JTextField();
                caixaCpf.setText(null);
                caixaCpf.setBackground(Color.WHITE);
                caixaCpf.setFont(new java.awt.Font("Tahoma",0,18));
                caixaCpf.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaCpfKeyReleased(evt);
                        }
                });
        }

        jLabel5.setFont(new java.awt.Font("Arial",0,24));
        jLabel5.setText("Email:");
        jLabel5.setForeground(new java.awt.Color(0,102,102));

        jLabel4.setFont(new java.awt.Font("Arial",0,24));
        jLabel4.setText("Numero do telefone:");
        jLabel4.setForeground(new java.awt.Color(0,102,102));
        {
                addFoto = new JButton();
                this.add(addFoto);
                this.add(jLabel9);
                this.add(c9);
                this.add(caixaFoto);
                caixaFoto.setBounds(275, 416, 416, 30);
                c9.setBounds(703, 416, 95, 27);
                jLabel9.setBounds(50, 417, 184, 22);
                addFoto.setText("Adiciona Foto");
                addFoto.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
                addFoto.setBounds(263, 541, 117, 25);
                addFoto.setFont(new java.awt.Font("Arial",0,12));
                addFoto.setBackground(new java.awt.Color(255,255,255));
                addFoto.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                                FotoPanel adFoto = new FotoPanel();
                                caixaFoto.setText(adFoto.retornaCaminho());
                                foto = adFoto.retornaCaminho();
                                c9.setText("OK");
                                c9.setForeground(Color.GREEN);
                                
                        }
                });
        }
        {
                caixaCpf2 = new JTextField();
                caixaCpf2.setText(null);
                caixaCpf2.setBackground(Color.WHITE);
                caixaCpf2.setFont(new java.awt.Font("Tahoma",0,18));
                caixaCpf2.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaCpf2KeyReleased(evt);
                        }
                });
        }
        {
                caixaCpf3 = new JTextField();
                caixaCpf3.setText(null);
                caixaCpf3.setBackground(Color.WHITE);
                caixaCpf3.setFont(new java.awt.Font("Tahoma",0,18));
                caixaCpf3.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaCpf3KeyReleased(evt);
                        }
                });
        }
        {
                caixaCpf4 = new JTextField();
                caixaCpf4.setText(null);
                caixaCpf4.setBackground(Color.WHITE);
                caixaCpf4.setFont(new java.awt.Font("Tahoma",0,18));
                caixaCpf4.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaCpf4KeyReleased(evt);
                        }
                });
        }

        jLabel8.setFont(new java.awt.Font("Arial",0,24));
        jLabel8.setText("Data de posse:");
        jLabel8.setForeground(new java.awt.Color(0,102,102));

        jLabel1.setFont(new java.awt.Font("Arial",0,24));
        jLabel1.setText("Nome do Diretor:");
        jLabel1.setForeground(new java.awt.Color(0,102,102));

        jLabel11.setFont(new java.awt.Font("Arial",0,36)); // NOI18N
        jLabel11.setText("Cadastrar dados do Diretor");
        jLabel11.setForeground(new java.awt.Color(0,102,102));
        jLabel11.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        {
                caixaPosse2 = new JTextField();
                caixaPosse2.setFont(new java.awt.Font("Tahoma",0,18));
                caixaPosse2.setText("MM");
                caixaPosse2.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                                if(caixaPosse2.isEditable()){
                                        caixaPosse2.setText("");
                                }
                                
                        }
                });
                caixaPosse2.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                try {
                                                caixaPosse2KeyReleased(evt);
                                        } catch (Exception e) {
                                                
                                                e.printStackTrace();
                                        }
                        }
                });
        }
        {
                caixaPosse3 = new JTextField();
                this.add(caixaPosse3);
                this.add(caixaPosse2);
                this.add(caixaPosse);
                this.add(jLabel8);
                this.add(c7);
                this.add(jLabel6);
                this.add(c6);
                this.add(caixaAdm);
                caixaAdm.setBounds(275, 330, 41, 30);
                c6.setBounds(444, 330, 86, 27);
                jLabel6.setBounds(31, 330, 200, 22);
                c7.setBounds(444, 376, 95, 23);
                jLabel8.setBounds(70, 372, 162, 29);
                caixaPosse.setBounds(275, 374, 41, 30);
                caixaPosse2.setBounds(330, 374, 41, 30);
                caixaPosse3.setFont(new java.awt.Font("Tahoma",0,18));
                caixaPosse3.setText("YYYY");
                caixaPosse3.setBounds(383, 374, 52, 30);
                caixaPosse3.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                                if(caixaPosse3.isEditable()){
                                        caixaPosse3.setText("");
                                }
                                
                        }
                });
                caixaPosse3.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                try {
                                                caixaPosse3KeyReleased(evt);
                                        } catch (Exception e) {
                                                
                                                e.printStackTrace();
                                        }
                        }
                });
        }
        {
                caixaAdm2 = new JTextField();
                this.add(caixaAdm2);
                caixaAdm2.setFont(new java.awt.Font("Tahoma",0,18));
                caixaAdm2.setText("MM");
                caixaAdm2.setBounds(330, 330, 41, 30);
                caixaAdm2.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                                if(caixaAdm2.isEditable()){
                                        caixaAdm2.setText("");
                                }
                                
                        }
                });
                caixaAdm2.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                try {
                                        caixaAdm2KeyReleased(evt);
                                } catch (Exception e) {
                                        
                                        e.printStackTrace();
                                }
                        }
                });
        }
        {
                caixaAdm3 = new JTextField();
                this.add(caixaAdm3);
                this.add(jLabel5);
                this.add(caixaMail);
                this.add(c5);
                c5.setBounds(703, 291, 74, 26);
                caixaMail.setBounds(275, 288, 416, 30);
                jLabel5.setBounds(164, 286, 67, 29);
                caixaAdm3.setFont(new java.awt.Font("Tahoma",0,18));
                caixaAdm3.setText("YYYY");
                caixaAdm3.setBounds(383, 330, 52, 30);
                caixaAdm3.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                                if(caixaAdm3.isEditable()){
                                        caixaAdm3.setText("");
                                }
                                
                        }
                });
                caixaAdm3.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                try {
                                        caixaAdm3KeyReleased(evt);
                                } catch (Exception e) {
                                        
                                        e.printStackTrace();
                                }
                        }
                });
        }
        {
                caixaTel1 = new JTextField();
                caixaTel1.setText(null);
                caixaTel1.setBackground(Color.WHITE);
                caixaTel1.setFont(new java.awt.Font("Tahoma",0,18));
                caixaTel1.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaTel1KeyReleased(evt);
                        }
                });
        }
        {
                caixaTel2 = new JTextField();
                this.add(caixaTel2);
                this.add(jLabel4);
                this.add(c4);
                this.add(caixaTel1);
                caixaTel1.setBounds(275, 238, 36, 30);
                c4.setBounds(459, 242, 95, 25);
                jLabel4.setBounds(12, 239, 219, 22);
                caixaTel2.setText(null);
                caixaTel2.setBackground(Color.WHITE);
                caixaTel2.setFont(new java.awt.Font("Tahoma",0,18));
                caixaTel2.setBounds(330, 238, 55, 30);
                caixaTel2.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaTel2KeyReleased(evt);
                        }
                });
        }
        {
                caixaTel3 = new JTextField();
                this.add(caixaTel3);
                this.add(jLabel3);
                this.add(caixaEnd);
                this.add(c3);
                this.add(c2);
                this.add(jLabel2);
                this.add(caixaCpf3);
                this.add(caixaCpf2);
                this.add(caixaCpf);
                this.add(caixaCpf4);
                this.add(c1);
                this.add(jLabel1);
                this.add(caixaNome);
                this.add(jLabel11);
                jLabel11.setBounds(176, 12, 446, 58);
                {
                	ponto = new JLabel();
                	this.add(ponto);
                	ponto.setText(" .");
                	ponto.setBounds(330, 156, 20, 22);
                	ponto.setForeground(new java.awt.Color(64,128,128));
                	ponto.setFont(new java.awt.Font("Arial",0,24));
                }
                {
                	jLabel7 = new JLabel();
                	this.add(jLabel7);
                	jLabel7.setText(" .");
                	jLabel7.setFont(new java.awt.Font("Arial",0,24));
                	jLabel7.setForeground(new java.awt.Color(64,128,128));
                	jLabel7.setBounds(405, 156, 20, 22);
                }
                {
                	jLabel10 = new JLabel();
                	this.add(jLabel10);
                	jLabel10.setText(" -");
                	jLabel10.setFont(new java.awt.Font("Arial",0,18));
                	jLabel10.setForeground(new java.awt.Color(64,128,128));
                	jLabel10.setBounds(486, 154, 20, 22);
                }
                caixaNome.setBounds(275, 113, 416, 29);
                jLabel1.setBounds(43, 113, 182, 26);
                c1.setBounds(703, 113, 95, 28);
                caixaCpf4.setBounds(511, 148, 36, 30);
                caixaCpf.setBounds(275, 148, 55, 30);
                caixaCpf2.setBounds(350, 148, 55, 30);
                caixaCpf3.setBounds(428, 148, 55, 30);
                c2.setBounds(565, 148, 95, 23);
                c3.setBounds(703, 190, 95, 27);
                caixaEnd.setBounds(275, 190, 416, 30);
                caixaTel3.setText(null);
                caixaTel3.setFont(new java.awt.Font("Tahoma",0,18));
                caixaTel3.setBounds(392, 238, 55, 30);
                caixaTel3.setBackground(Color.WHITE);
                caixaTel3.addKeyListener(new KeyAdapter() {
                        public void keyReleased(KeyEvent evt) {
                                caixaTel3KeyReleased(evt);
                        }
                });
        }

        jLabel2.setFont(new java.awt.Font("Arial",0,24));
        jLabel2.setText("Numero do cpf:");
        jLabel2.setForeground(new java.awt.Color(0,102,102));
        jLabel2.setBounds(62, 148, 166, 29);

        jLabel3.setFont(new java.awt.Font("Arial",0,24));
        jLabel3.setText("Endereco:");
        jLabel3.setForeground(new java.awt.Color(0,102,102));
        jLabel3.setBounds(122, 190, 110, 25);

        cadastra.setText("Cadastrar");
        cadastra.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        cadastra.setBounds(396, 541, 117, 25);
        cadastra.setFont(new java.awt.Font("Arial",0,12));
        cadastra.setBackground(new java.awt.Color(255,255,255));
        cadastra.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                try {
                                        cadastraMouseClicked(evt);
                                } catch (Exception e) {
                                        
                                        e.printStackTrace();
                                }
            }
        });

        cancelar.setText("Cancelar");
        cancelar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        cancelar.setBounds(666, 541, 117, 25);
        cancelar.setFont(new java.awt.Font("Arial",0,12));
        cancelar.setBackground(new java.awt.Color(255,255,255));
        cancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cancelarMouseClicked(evt);
            }
        });

        limpar.setText("Limpar");
        limpar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        limpar.setBounds(533, 541, 117, 25);
        limpar.setFont(new java.awt.Font("Arial",0,12));
        limpar.setBackground(new java.awt.Color(255,255,255));
        limpar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                limparMouseClicked(evt);
            }
        });

        caixaNome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                caixaNomeKeyReleased(evt);
                
            }
        });

        caixaEnd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                caixaEndKeyReleased(evt);
            }
        });

        caixaMail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                caixaMailKeyReleased(evt);
            }
        });

        caixaAdm.addKeyListener(new KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                        try {
                                caixaAdmKeyReleased(evt);
                        } catch (Exception e) {
                                
                                e.printStackTrace();
                        }
                }
        });

        caixaPosse.addKeyListener(new KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                        try {
                                        caixaPosseKeyReleased(evt);
                                } catch (Exception e) {
                                        
                                        e.printStackTrace();
                                }
                }
        });

        caixaFoto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                caixaFotoKeyReleased(evt);
            }
        });

    }// </editor-fold>
    
    protected void caixaAdm3KeyReleased(KeyEvent evt) throws Exception {
        String ano = caixaAdm3.getText();
        if (ano.length() == 4) {
                if (teclaPressionada(evt)) {
                        caixaAdm3.setEditable(true);
                } else {
                        caixaAdm3.setEditable(false);
                }
        }
        anoAdm = ano;
        String data = diaAdm +"/"+ mesAdm +"/"+ anoAdm;
        try {
                Data dt = new Data(data);
        } catch (Exception e) {
                c6.setForeground(Color.RED);
                c6.setText("INVALIDO");
                return;
        }
        c6.setForeground(Color.GREEN);
        c6.setText("OK");
        this.dataAdmissao = new Data(data);
                
        }

        protected void caixaAdm2KeyReleased(KeyEvent evt) throws Exception {
        String mes = caixaAdm2.getText();
        if (mes.length() == 2) {
                if (teclaPressionada(evt)) {
                        caixaAdm2.setEditable(true);
                } else {
                        caixaAdm2.setEditable(false);
                }
        }
        mesAdm = mes;
        String data = diaAdm +"/"+ mesAdm +"/"+ anoAdm;
        try {
                Data dt = new Data(data);
        } catch (Exception e) {
                c6.setForeground(Color.RED);
                c6.setText("INVALIDO");
                return;
        }
        c6.setForeground(Color.GREEN);
        c6.setText("OK");
        this.dataAdmissao = new Data(data);
                
        }

        private void cadastraMouseClicked(java.awt.event.MouseEvent evt) throws Exception { 
        for(Component component: this.getComponents()){
            if(component instanceof JLabel){
                if(component.getForeground().equals(Color.RED)){
                        JOptionPane.showMessageDialog(null,"Algum dado invalido");
                        return;
                }
            }
        }
       String cargo = "Diretor";
        GerenciadorDeJanelas.diretor = (new Diretor(nome, cpf,
                endereco, telefone, email, dataAdmissao, dataPosse, foto, cargo, GerenciadorDeJanelas.todasMatriculas));
        GerenciadorDeJanelas.todasMatriculas.add(GerenciadorDeJanelas.diretor.getMatricula());
        

                // grava Diretor criado em um xml
                GerenciadorDeJanelas.gravar(GerenciadorDeJanelas.arquivoDiretor,
                                GerenciadorDeJanelas.ARQUIVADOR
                                                .toXML(GerenciadorDeJanelas.diretor));
                // transforma em xml
                String xmlMatricula = GerenciadorDeJanelas.ARQUIVADOR
                                .toXML(GerenciadorDeJanelas.todasMatriculas);
                // grava o arrayXml no arquivo
                GerenciadorDeJanelas.gravar(GerenciadorDeJanelas.arquivoDeMatriculas,
                                xmlMatricula);
        
        limparMouseClicked(evt);
        GerenciadorDeJanelas.window.setContentPane(GerenciadorDeJanelas.menuCadastra);
        GerenciadorDeJanelas.window.setVisible(true);
        
}                                     

    private void cancelarMouseClicked(java.awt.event.MouseEvent evt) {                                      
        limparMouseClicked(evt);
        GerenciadorDeJanelas.window.setContentPane(GerenciadorDeJanelas.menuCadastra);
        GerenciadorDeJanelas.window.setVisible(true);
}                                     

    private void limparMouseClicked(java.awt.event.MouseEvent evt) {                                    
        for(Component component: this.getComponents()){
            if(component instanceof JTextField){
                JTextField caixa = (JTextField)component;
                caixa.setEditable(true);
                caixa.setText("");
            }
            
        }
        c1.setText("");c2.setText("");c3.setText("");c4.setText("");c5.setText("");c6.setText("");c7.setText("");c9.setText("");
        
        
}                                   

    private void caixaNomeKeyReleased(java.awt.event.KeyEvent evt) {                                      
        String nome = caixaNome.getText();
        if(!Validadores.validaNome(nome)){
                c1.setForeground(Color.RED);
            c1.setText("INVALIDO");
            flag = false;
        }else{
            c1.setForeground(Color.GREEN);
            c1.setText("Ok");
        }
        this.nome = nome;
}                                     
    private boolean teclaPressionada(KeyEvent ke){  
        if ( ke.getKeyCode() == KeyEvent.VK_BACK_SPACE ){
                return true;
        }
            return false;
    }

    
private void caixaCpfKeyReleased(java.awt.event.KeyEvent evt) {                                     
         String cpf = caixaCpf.getText();
     if(cpf.length() == 3){
        if(teclaPressionada(evt)){
                caixaCpf.setEditable(true);
        }else{
                caixaCpf.setEditable(false);
        }
     }
     
     this.cpf1 = cpf;
     this.cpf = cpf1+"."+cpf2+"."+cpf3+"-"+cpf4;
     if(!Validadores.validaCpf(this.cpf)){
        c2.setForeground(Color.RED);
        c2.setText("INVALIDO");
     }else{
        c2.setForeground(Color.GREEN);
        c2.setText("OK");
     }
}                                    

private void caixaEndKeyReleased(java.awt.event.KeyEvent evt) {                                     
    String end = caixaEnd.getText();
    if(!Validadores.validaEndereco(end)){
        c3.setForeground(Color.RED);
        c3.setText("INVALIDO");
        flag = false;
    }else{
        c3.setForeground(Color.GREEN);
        c3.setText("Ok");
        this.endereco = end;
    }
}                                    

private void caixaTel1KeyReleased(java.awt.event.KeyEvent evt) {                                     
        String tel = caixaTel1.getText();
    if(tel.length() == 2){
        if(teclaPressionada(evt)){
                caixaTel1.setEditable(true);
        }else{
                caixaTel1.setEditable(false);
        }
    }

        telefone1 = tel;
        telefone = "("+telefone1+")"+telefone2+"-"+telefone3;
        if(!Validadores.validaTelefone(telefone)){
                c4.setForeground(Color.RED);
                c4.setText("INVALIDO");
        }else{
                c4.setForeground(Color.GREEN);
                c4.setText("OK");
        }
}                                    

private void caixaMailKeyReleased(java.awt.event.KeyEvent evt) {                                      
    String mail = caixaMail.getText();
    if(!Validadores.validaEmail(mail)){
        c5.setForeground(Color.RED);
        c5.setText("INVALIDO");
        flag = false;
    }else{
        c5.setForeground(Color.GREEN);
        c5.setText("Ok");
        this.email = mail;
    }
}                                     

private void caixaAdmKeyReleased(java.awt.event.KeyEvent evt) throws Exception {                                     
        String dia = caixaAdm.getText();
        if (dia.length() == 2) {
                if (teclaPressionada(evt)) {
                        caixaAdm.setEditable(true);
                } else {
                        caixaAdm.setEditable(false);
                }
        }
        diaAdm = dia;
        String data = diaAdm +"/"+ mesAdm +"/"+ anoAdm;
        try {
                Data dt = new Data(data);
        } catch (Exception e) {
                c6.setForeground(Color.RED);
                c6.setText("INVALIDO");
                return;
        }
        c6.setForeground(Color.GREEN);
        c6.setText("OK");
        this.dataAdmissao = new Data(data);
}                                    

private void caixaPosseKeyReleased(java.awt.event.KeyEvent evt) throws Exception {                                       
        String dia = caixaPosse.getText();
        if (dia.length() == 2) {
                if (teclaPressionada(evt)) {
                        caixaPosse.setEditable(true);
                } else {
                        caixaPosse.setEditable(false);
                }
        }
        diaPosse = dia;
        String data = diaPosse + "/" + mesPosse + "/" + anoPosse;
        try {
                Data dataPosse = new Data(data);
        } catch (Exception e) {
                c7.setForeground(Color.RED);
                c7.setText("Invalido");
                return;
        }
        c7.setForeground(Color.GREEN);
        c7.setText("OK");
        this.dataPosse = new Data(data);
}                                      

private void caixaFotoKeyReleased(java.awt.event.KeyEvent evt) {
        if(foto != null){
    String caminho = caixaFoto.getText();
    if(foto.length() < 2){
        c9.setForeground(Color.RED);
        c9.setText("INVALIDO");
    }else{
        c9.setForeground(Color.GREEN);
        c9.setText("Ok");
    }
    this.foto = caminho;
        }else{
                
        }
}                                     

        private void caixaCpf2KeyReleased(KeyEvent evt) {
                String cpf = caixaCpf2.getText();
        if(cpf.length() == 3){
                if(teclaPressionada(evt)){
                        caixaCpf2.setEditable(true);
                }else{
                        caixaCpf2.setEditable(false);
                }
        }
        this.cpf2 = cpf;
        this.cpf = cpf1+"."+cpf2+"."+cpf3+"-"+cpf4;
        if(!Validadores.validaCpf(this.cpf)){
                c2.setForeground(Color.RED);
                c2.setText("INVALIDO");
        }else{
                c2.setForeground(Color.GREEN);
                c2.setText("OK");
        }
        }
        
        private void caixaCpf3KeyReleased(KeyEvent evt) {
                String cpf = caixaCpf3.getText();
        if(cpf.length() == 3){
                if(teclaPressionada(evt)){
                        caixaCpf3.setEditable(true);
                }else{
                        caixaCpf3.setEditable(false);
                }
        }
        this.cpf3 = cpf;
        this.cpf = cpf1+"."+cpf2+"."+cpf3+"-"+cpf4;
        if(!Validadores.validaCpf(this.cpf)){
                c2.setForeground(Color.RED);
                c2.setText("INVALIDO");
        }else{
                c2.setForeground(Color.GREEN);
                c2.setText("OK");
        }
        }
        
        private void caixaCpf4KeyReleased(KeyEvent evt) {
                String cpf = caixaCpf4.getText();
        if(cpf.length() == 2){
                if(teclaPressionada(evt)){
                        caixaCpf4.setEditable(true);
                }else{
                        caixaCpf4.setEditable(false);
                }
        }


        this.cpf4 = cpf;
        this.cpf = cpf1+"."+cpf2+"."+cpf3+"-"+cpf4;
        if(!Validadores.validaCpf(this.cpf)){
                c2.setForeground(Color.RED);
            c2.setText("INVALIDO");
        }else{
                c2.setForeground(Color.GREEN);
            c2.setText("OK");
        }
        }
        
        private void caixaTel2KeyReleased(KeyEvent evt) {
                String tel = caixaTel2.getText();
                if(tel.length() == 4){
                if(teclaPressionada(evt)){
                        caixaTel2.setEditable(true);
                }else{
                        caixaTel2.setEditable(false);
                }
        }
                
                this.telefone2 = tel;
                telefone = "("+telefone1+")"+telefone2+"-"+telefone3;
                if(!Validadores.validaTelefone(telefone)){
                        c4.setForeground(Color.RED);
                        c4.setText("INVALIDO");
                }else{
                        c4.setForeground(Color.GREEN);
                        c4.setText("OK");
                }
        }
        
        private void caixaTel3KeyReleased(KeyEvent evt) {
                String tel = caixaTel3.getText();
                if(tel.length() == 4){
                if(teclaPressionada(evt)){
                        caixaTel3.setEditable(true);
                }else{
                        caixaTel3.setEditable(false);
                }
        }
                if(tel.length() == 4){
                        c4.setForeground(Color.GREEN);
                c4.setText("OK");
                
                }else{
                        c4.setForeground(Color.RED);
                c4.setText("INVALIDO");
                return;
                }
                this.telefone3 = tel;
                telefone = "("+telefone1+")"+telefone2+"-"+telefone3;
                if(!Validadores.validaTelefone(telefone)){
                        caixaTel3.setBackground(Color.RED);
                        c4.setText("INVALIDO");
                }else{
                        c4.setForeground(Color.GREEN);
                        c4.setText("OK");
                }
        }
        
        private void caixaPosse2KeyReleased(KeyEvent evt) throws Exception {
                String mes = caixaPosse.getText();
                if (mes.length() == 2) {
                        if (teclaPressionada(evt)) {
                                caixaPosse.setEditable(true);
                        } else {
                                caixaPosse.setEditable(false);
                        }
                }
                mesPosse = mes;
                String data = diaPosse + "/" + mesPosse + "/" + anoPosse;
                try {
                        Data dataPosse = new Data(data);
                } catch (Exception e) {
                        c7.setForeground(Color.RED);
                        c7.setText("Invalido");
                        return;
                }
                c7.setForeground(Color.GREEN);
                c7.setText("OK");
                this.dataPosse = new Data(data);
        }
        
        private void caixaPosse3KeyReleased(KeyEvent evt) throws Exception {
                String ano = caixaPosse.getText();
                if (ano.length() == 4) {
                        if (teclaPressionada(evt)) {
                                caixaPosse.setEditable(true);
                        } else {
                                caixaPosse.setEditable(false);
                        }
                }
                anoPosse = ano;
                String data = diaPosse + "/" + mesPosse + "/" + anoPosse;
                try {
                        Data dataPosse = new Data(data);
                } catch (Exception e) {
                        c7.setForeground(Color.RED);
                        c7.setText("Invalido");
                        return;
                }
                c7.setForeground(Color.GREEN);
                c7.setText("OK");
                this.dataPosse = new Data(data);
        }

    // Variables declaration - do not modify
    private javax.swing.JLabel c1;
    private javax.swing.JLabel c2;
    private javax.swing.JLabel c3;
    private javax.swing.JLabel c4;
    private javax.swing.JLabel c5;
    private javax.swing.JLabel c6;
    private javax.swing.JLabel c7;
    private javax.swing.JLabel c9;
    private javax.swing.JButton cadastra;
    private javax.swing.JTextField caixaAdm;
    private javax.swing.JTextField caixaEnd;
    private javax.swing.JTextField caixaFoto;
    private javax.swing.JTextField caixaMail;
    private javax.swing.JTextField caixaNome;
    private JTextField caixaCpf4;
    private JTextField caixaCpf3;
    private JTextField caixaCpf2;
    private JTextField caixaCpf;
    private javax.swing.JTextField caixaPosse;
    private javax.swing.JButton cancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JButton limpar;
    // End of variables declaration

}
